<?php

use Biz\service\search\Goods;
use Doraemon\tools\ActionLog;
use Biz\tools\GoodsExposureLog;
use Biz\service\trade\UserAddress;
use Biz\service\SearchGoods as sSearchGoods;

/**
 * @deprecated
 */
class SearchGoodsAction extends ActionPlugin
{
    public function main()
    {
        $actionLogMap = [
            'default',
            'new',
            'price_asc',
            'price_desc',
        ];

        $keyword = $this->getRequest()->getQuery('keyword', '床');
        $sort = $this->getRequest()->getQuery('sort_type', 0);
        $province_id = $this->getRequest()->getQuery('province_id', 0);
        $cityId = $this->getRequest()->getQuery('city_id', 0);
        $page = $this->getRequest()->getQuery('page', 1);

        $areaCode = $cityId ? $cityId : $province_id;
        $areaCode = $areaCode ?:UserAddress::getUserDefaultCityCode($this->uid);

        $goodsList = sSearchGoods::searchGoodsByMallTab($keyword, $sort, $areaCode, $this->uid, $page);

        ActionLog::log($this->uid, ['keyword' => $keyword, 'page' => $page, 'sort_type' => $actionLogMap[$sort]], ActionLog::BIZ_SEARCH_GOODS);

        $this->setSuccess($goodsList);
        GoodsExposureLog::addLog($this->getRequest(), $goodsList,$keyword);
    }
}